<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<meta name="GENERATOR" content="Microsoft FrontPage 5.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>JavaScript in Synchronet</title>
</head>

<body>

<h1><span style="FONT-FAMILY: Arial">JavaScript in Synchronet</span></h1>
<p class="MsoNormal"><span style="font-family: Arial">Synchronet </span><span style="FONT-FAMILY: Arial">
uses <a href="http://mozilla.org/js/spidermonkey">Mozilla's JavaScript engine</a>
for its preferred local scripting environment.<br>
</p>

You can learn about the core JavaScript language and object model from the
following  documents:<o:p>
</o:p>
</span></p>
<ul style="MARGIN-TOP: 0in" type="disc">
  <li class="MsoNormal" style="mso-list: l2 level1 lfo5; tab-stops: list .5in">
  <span style="font-family: Arial"><a href="http://developer.mozilla.org/en/JavaScript/Guide">
  Core JavaScript Guide</a></span></li>
  <li class="MsoNormal" style="mso-list: l2 level1 lfo5; tab-stops: list .5in">
  <span style="font-family: Arial"><a href="http://developer.mozilla.org/en/JavaScript/Reference">Core JavaScript Reference
  </a></span></li>
  <li class="MsoNormal" style="mso-list: l2 level1 lfo5; tab-stops: list .5in">
  <span style="font-family: Arial">
  <a href="http://developer.mozilla.org/docs/JavaScript">More Mozilla 
  JavaScript documents</a></span></li>
</ul>
<p class="MsoNormal"><span style="FONT-FAMILY: Arial">JavaScript is an
established, mature scripting language syntactically similar to C++ and Java.
<p><a href="js/guide/intro.html#1012569">
JavaScript is <b>not Java</b></a>. <o:p>
</o:p>
</span></p>
<p class="MsoNormal"><span style="FONT-FAMILY: Arial">The ECMA and ISO standards
organizations have standardized the core JavaScript language in <a href="http://developer.netscape.com/docs/javascript/e262-pdf.pdf">ECMA-262</a>
(ECMAScript) and ISO-16262.<o:p>
</o:p>
</span></p>
<h2><span style="font-family: Arial">Baja and JavaScript</span></h2>
<p><span style="font-family: Arial"><a href="baja.html">Baja</a> is the original
scripting language of Synchronet (introduced in v2.0), used to create
Synchronet-specific <i>modules</i> and <i>command shells</i>. Baja was
originally designed as a simple BASIC-like language for controlling the display
of menus and command prompts, accepting commands from the user and passing on
control to high-level BBS functions. Over the years, Baja has been extended and
enhanced to allow a high-level of functionality, but it was never going to reach
the power and flexibility of JavaScript.</span></p>
<p><span style="font-family: Arial">For example Baja modules and command shells,
see the <b><samp>.src</samp></b> files in your Synchronet <b><code>exec</code></b> directory.</span></p>
<p><span style="font-family: Arial">For the foreseeable future Baja modules and
command-shells will continue to be supported in Synchronet, but sysops and
developers are encouraged to use JavaScript instead of Baja moving forward. With
very few exceptions, everything that can be done in a Baja module can be done in
a JavaScript module, and much much more.</span></p>
<p><span style="font-family: Arial">Eventually, all the stock command-shells and
external modules will be converted to JavaScript.</span></p>
<h2><span style="font-family: Arial">JavaScript Files</span></h2>
<p><span style="font-family: Arial">JavaScript files are just ASCII text files.
They are normally named with a <b><code>.js</code></b> file extension
and located in your Synchronet <b><samp>exec</samp></b> directory or with a <b><code>.ssjs</code></b>
and located in your Synchronet <b><samp>web</samp></b> hierarchy. JavaScript files do not need to be compiled.
JavaScript files are loaded into memory at the time of execution, so a change to
a JavaScript file will take effect the next time that file is executed (no recycling of servers is normally required).</span></p>
<p><span style="font-family: Arial">For example JavaScript modules and services,
see the <b><samp>.js</samp></b> files in your Synchronet <b><code>exec</code></b> directory.
<p>
Modified stock <b><samp>.js</samp></b> files should be placed in your Synchronet <b><code>mods</code></b> directory to prevent
over-writing by future upgrades.
</span></p>
<h2><span style="font-family: Arial">Integration</span></h2>
<p><span style="font-family: Arial">JavaScript files can be executed from:</span></p>

<ul>
  <li><b><span style="font-family: Arial">Terminal</span></b><span style="font-family: Arial"><b> Server</b>&nbsp;<br>
 as a timed event, external program (door), login/logon/newuser module,<br>
    basically anywhere a Baja module or executable can be launched</span></li>
  <li><span style="font-family: Arial"><b>Web Server</b><br>
    dynamically generates HTML files<br>
    see <samp>web/root/*.ssjs</samp></span>
  <li><span style="font-family: Arial"><b>FTP Server</b><br>
    dynamically generates HTML index files<br>
    see <samp>exec/ftp-html.js</samp> and <samp>exec/ftp-web-html.js</samp></span></li>
  <li><span style="font-family: Arial"><b>Services</b><br>
    Synchronet services (both static and dynamic) are usually written in
    JavaScript<br>
    see <samp>exec/*service.js</samp> and <samp>ctrl/services.ini</samp></span></li>
  <li><span style="font-family: Arial"><b>Mail Server</b><br>
    inbound mail processors may be written in JavaScript<br>
  see <samp>exec/mailproc_util.js</samp> and <samp>ctrl/mailproc.ini</samp></span></li>
  <li><b><span style="font-family: Arial">JSexec</span></b><span style="font-family: Arial"><br>
    some script files may be executed outside of Synchronet (e.g. as a CGI 
  script or daemon) using <i>jsexec</i><br>
  examples: <samp>ircd.js, newslink.js</samp></span></li>
</ul>
<p><span style="font-family: Arial">From the Terminal Server, a JavaScript file is executed on a native command-line
by placing a question mark (<samp>?</samp>) at the beginning of the command-line
before the JavaScript file name (in SCFG). It is not necessary to specify the <b><samp>.js</samp></b>
portion of the file name on the command-line. For example, the command-line to execute
the file <tt>exec/newslink.js</tt> would be &quot;<tt>?newslink</tt>&quot; or 
&quot;<tt>?newslink.js</tt>&quot;.</span></p>

<p><span style="font-family: Arial">From within a Baja module, a JavaScript file 
may be executed using the following Baja code:<br>
</span><font face="Courier New">exec &quot;?modname&quot;</font><span style="font-family: Arial"> 
where <i>modname </i>is the JavaScript file.</span></p>

<h2><span style="font-family: Arial">Object Model (methods and properties)</span></h2>
<p><span style="font-family: Arial">Synchronet has its own constantly evolving JavaScript object
model, not to be confused with the Document Object Model (DOM) used in web
browsers. In order to fully understand the capabilities of JavaScript modules in
Synchronet, you must familiarize yourself with <a href="js/ref/index.html">Core
JavaScript</a> as well as the <a href="jsobjs.html">Synchronet JavaScript Object
Model</a>.</span></p>

<p align="right"><font face="Arial,Helvetica" size="1">
$Id: js.html,v 1.9 2011/10/21 02:35:04 rswindell Exp $</font>
</p>

</body>

</html>